feat: add Bvh::cast_ray_best for SIMD-accelerated generic ray queries#412
Open
zmerlynn wants to merge 1 commit intodimforge:masterfrom
Open
feat: add Bvh::cast_ray_best for SIMD-accelerated generic ray queries#412zmerlynn wants to merge 1 commit intodimforge:masterfrom
zmerlynn wants to merge 1 commit intodimforge:masterfrom
Conversation
cast_local_ray_and_get_normal on CompositeShapeRef was calling find_best() directly with the non-SIMD BvhNode::cast_ray for AABB tests, missing the SIMD-accelerated path available on f32/dim3 builds. Add Bvh::cast_ray_best — a generic version of cast_ray that returns any BvhLeafCost type (not just Real) with proper SIMD/non-SIMD dispatch. Change cast_local_ray_and_get_normal to use it. This means TriMesh::cast_local_ray_and_get_normal (and all composite shapes using this code path) now benefits from SIMD AABB tests on supported platforms, matching the existing cast_local_ray behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CompositeShapeRef::cast_local_ray_and_get_normalcallsbvh().find_best()directly withBvhNode::cast_rayas the AABB cost function. This always uses the non-SIMD ray-AABB test, even onf32/dim3/simd-is-enabledbuilds wherecast_inv_ray_simdis available.Meanwhile, the sibling method
cast_local_raycallsbvh().cast_ray()which does dispatch to the SIMD path. SoTriMesh::cast_local_raygets SIMD butTriMesh::cast_local_ray_and_get_normaldoes not — a surprising inconsistency.The root cause:
Bvh::cast_rayreturnsOption<(u32, Real)>, so it can't be used when the caller needsRayIntersection(which includes the surface normal). The caller was forced to usefind_bestdirectly and provide its own (non-SIMD) AABB cost closure.Solution
Add
Bvh::cast_ray_best<L: BvhLeafCost>— identical tocast_raybut generic over the return type. Two#[cfg]-gated variants provide the same SIMD/non-SIMD dispatch ascast_ray:RayIntersectionalready implementsBvhLeafCost(returnstime_of_impactas cost), socast_local_ray_and_get_normalcan now simply callbvh().cast_ray_best(...).Test plan
cargo test— all 520 tests pass across parry2d, parry2d-f64, parry3d, parry3d-f64cargo fmt -- --checkRUSTFLAGS="-D warnings" cargo clippyRUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-depscast_ray_bestwith proper feature gate🤖 Generated with Claude Code